package client

import (
	. "npxy-go/pkg/proxy/message"
	"npxy-go/pkg/tcp"
	"npxy-go/pkg/tcp/handlers"
)

func Start(conf *Config) error {
	bridge := tcp.NewClient(func(pipe tcp.Pipeline) {
		pipe.AddHandlerChain(
			handlers.NewLengthHeadHandler(),
			handlers.NewClientAuthorizeHandler(conf.Secret),
			&bridgeHandler{localSessions: NewSessionChannelManager(), conf: conf},
		)
	})

	bridge.ReadBufferSize = tcp.DefaultReadBufferSize + TotalHeadSize
	bridge.ReadHeadSize = 0

	return bridge.Connect(conf.Bridge)
}
